home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5479 < prev    next >
Encoding:
Text File  |  1996-08-05  |  850 b   |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: bcarh8ab.bnr.ca!CompStar!tzinck
  3. From: tzinck@bnr.ca 
  4. Subject: embedded strtok() calls on different strings?
  5. Originator: tzinck@bcarhb35
  6. Message-ID: <DMGrn7.1Bx0@CompStar.bnr.ca>
  7. Sender: tzinck@bnr.ca (Thomas Zinck)
  8. Date: Thu, 8 Feb 1996 15:42:43 GMT
  9. Nntp-Posting-Host: bcarhb35
  10. Organization: Bell-Northern Research Ltd.
  11.  
  12.  
  13. Hello.
  14.  
  15.  
  16. I want to do the following:
  17.  
  18.  
  19. char *string1="This is string one";
  20. char *string2="This is string two";
  21.  
  22. void *vp1;
  23. void *vp2;
  24.  
  25. vp1 = strtok(string1," ");
  26.  
  27. while (vp1 != NULL){
  28.     printf("Tok1 = %s\n", (char *) vp1);
  29.  
  30.     vp2 = strtok(string2," ");
  31.     while (vp2!=NULL){
  32.         printf("Tok2 = %s\n", (char *) vp2);
  33.         vp2 = strtok(NULL, " ");
  34.     }
  35.  
  36.     vp1 = strtok(NULL, " ");
  37. }
  38.  
  39. But the output is :
  40. Tok1 = This
  41. Tok2 = This
  42. Tok2 = is
  43. Tok2 = string
  44. Tok2 = two
  45.  
  46.  
  47. as vp1 gets corrupted. Any thoughts ?
  48.  
  49. -Tom
  50.     
  51.  
  52.